
package cup.modules.visual.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cup.core.log.exception.ServiceException;
import cup.core.tool.constant.CupConstant;
import cup.core.tool.utils.Func;
import cup.modules.visual.entity.VisualCategory;
import cup.modules.visual.mapper.VisualCategoryMapper;
import cup.modules.visual.service.IVisualCategoryService;
import org.springframework.stereotype.Service;

/**
 * 可视化分类表 服务实现类
 *
 * @author CUP
 */
@Service
public class VisualCategoryServiceImpl extends ServiceImpl<VisualCategoryMapper, VisualCategory> implements IVisualCategoryService {

	@Override
	public boolean submit(VisualCategory visualCategory) {
		LambdaQueryWrapper<VisualCategory> lqw = Wrappers.<VisualCategory>query().lambda().eq(VisualCategory::getCategoryValue, visualCategory.getCategoryValue());
		Long cnt = Long.valueOf(baseMapper.selectCount((Func.isEmpty(visualCategory.getId())) ? lqw : lqw.notIn(VisualCategory::getId, visualCategory.getId())));
		if (cnt > 0L) {
			throw new ServiceException("当前模块键值已存在!");
		}
		visualCategory.setIsDeleted(CupConstant.DB_NOT_DELETED);
		return saveOrUpdate(visualCategory);
	}

}
